package com.lbs.jiepiaisi.base;


import android.util.Log;

import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by yu on 2019/12/17.
 */

public abstract class BaseObserver<T extends BaseResponseEntity> implements Observer<T> {
	@Override
	public void onNext(T t) {
//		Log.e("BaseObserverOnNext", "8888888");
		if (t.getCode() == 0) {
//			Log.e("BaseObserverSuccess", "7777777");
			onSuccess(t);
		} else {
			Log.e("BaseObserverFailure", "6666666");
			//onFailure(new Exception(t.getMsg()), t.getMsg(), t.getCode());
		}
	}

	public BaseObserver(){}

	@Override
	public void onError(@NonNull Throwable e) {
		Log.e("BaseObserverFailure", "555555");
		onFailure(RxExceptionUtil.exceptionHandler(e));
	}

	@Override
	public void onComplete() {}

	@Override
	public void onSubscribe(@NonNull Disposable d) {}


	public abstract void onSuccess(T result);

	public abstract void onFailure(ErrorException e);
}
